public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str1 = sc.nextLine();
            String str2 = sc.nextLine();
            if(str1.length() < str2.length()){
                System.out.println(maxCommonLength(str1,str2));
            }else{
                System.out.println(maxCommonLength(str2,str1));
            }
        }
    }
    
    public static String maxCommonLength(String s1, String s2){
        String result = ""; //记录最长的子串
        for(int i = 1; i < s1.length(); i++){
            StringBuilder str = new StringBuilder();
            for(int j = i - 1; j < s1.length(); j++){
                if(s2.contains(str.append(s1.charAt(j)))){
                    if(str.length() > result.length()){
                        result = str.toString();
                    }
                }
            }
        }
        return result;
    }
}